<template>
  <view class="point-detail">
    <view class="good" v-if="isCouponProduct != 1">
      <img :src="ware.waresPic" alt="" srcset="" />
    </view>

    <view class="center" v-else>
      <template v-if="!showTip">
        <template v-if="couponList.length != 0">
          <view class="title">此次兑换包含以下优惠劵</view>
          <view
            class="coupon"
            :class="[
              ele.couponType == 1 ? 'direct' : '',
              ele.couponType == 2 ? 'rate' : '',
              ele.couponType == 3 ? 'exchange' : '',
              ele.couDrawStatus == '1' ? 'expired' : '',
            ]"
            v-for="ele in couponList"
            :key="ele.couponTemplateId"
          >
            <view class="left">
              <view
                class="amount"
                v-if="ele.couponType == 1 "
              >
                ￥
                <text class="value">{{ ele.couponAmt }}</text>
              </view>
              <view
                class="amount"
                v-if="ele.couponType == 2"
              >
                <text class="value">{{ ele.couponAmt }}</text>
                %
              </view>
              <view class="condition">
                {{
                  couponListInfo.couponThresholdAmt == 0
                    ? "无门槛"
                    : "满" + couponListInfo.couponThresholdAmt + "元可用"
                }}
              </view>
              <view class="exchangeName">{{ ele.couponName }}</view>
            </view>
            <view class="right">
              <view class="title">
                <text class="type"
                  >{{ ele.couponType == 1 ? "立减劵" : ""
                  }}{{ ele.couponType == 2 ? "折扣劵" : ""
                  }}{{ ele.couponType == 3 ? "兑换劵" : "" }}
                </text>
                <text class="state">
                  {{ ele.couDrawStatus == 0 ? "可尝试领取" : "" }}
                  {{ ele.couDrawStatus == 1 ? "已领取" : "" }}
                  {{ ele.couDrawStatus == 2 ? "领取失败" : "" }}
                  <!-- 
                  {{ ele.showStatus == 1 ? "优惠券已领完" : "" }}
                  {{ ele.showStatus == 2 ? "不满足领取条件" : "" }}
                  {{ ele.showStatus == 3 ? "不符合领取条件" : "" }} 
                  -->
                </text>
              </view>
              <view class="content">
                <view class="items">
                  <view class="item scope">
                    适用：<text
                      >{{
                        ele.couponType == 1 || ele.couponType == 2
                          ? ele.couponStaNames
                          : ""
                      }}{{
                        ele.couponType == 3
                          ? ele.verStaNames
                          : ""
                      }}
                      
                      </text
                    >
                  </view>
                  <view class="item valid">
                    截止：<text>{{
                      (ele.effectiveTimeType == 1
                        ? (ele.effectiveTimeEnd || "").replace(
                            /\s{1,}\S{8,8}/,
                            ""
                          )
                        : "") +
                      (ele.effectiveTimeType == 2
                        ? "领取后" + ele.effectiveDayNum + "天有效"
                        : "")
                    }}</text>
                  </view>
                  <view class="item from">来源：<text>加油活动</text></view>
                </view>
                <!-- <view class="btn">
                  <button @click="getCoupon([ele.couponTemplateId])">
                    领取
                  </button>
                </view> -->
              </view>
              <view class="tip">
                {{
                  !!ele.couponDetails
                    ? ele.couponDetails
                    : "使用此劵更优惠~更多活动，请关注我们的公众号！"
                }}
              </view>
            </view>
          </view>
        </template>
        <template v-else>
          <view style="text-align: center">当前活动里没有可有优惠券~</view>
        </template>
      </template>
      <template v-else>
        <view style="text-align: center">{{ tip }}</view>
      </template>
    </view>

    <view class="title">
      <view class="text">{{ ware.waresName }}</view>
      <view class="price">
        <text class="icon"></text>
        <text class="amount">{{ ware.saleIntegral }}</text>
      </view>
      <view class="sold">已兑换 {{ ware.waresOutCount }}</view>
    </view>


    <!-- <view class="selected">
      <view class="text">已选</view>
      <view class="content">儿童情商课+智慧课堂,1</view>
      <view class="icon"></view>
    </view> -->
    <!-- <view class="pictures">
      <view class="text">- 图文详情 -</view>
    </view> -->
    <view class="buy">
      <button @click="exchange">立刻兑换</button>
    </view>
  </view>
</template>

<script>
import { mapActions, mapState, mapGetters } from "vuex";
export default {
  head() {
    return {
      title: "积分商品详情页",
    };
  },
  data() {
    return {
      ware: {},
      wareList: [],
      pointInfo: {},
      id: '',
      couponList: [],
      couponListInfo:{},
      isCouponProduct: 0,
      sid: '',
    };
  },
  onLoad(e) {
		this.sid = e.sid;
		this.id = e.id;
  },
  mounted() {
    this.init();
  },
  computed: {

  },
  methods: { 
    async init() {
      try {
        const {phoneNumber, enterpriseId} = this;
        const res = await this.$Request({
          url: "/getCustomerPointsInfo",
          method: "GET",
          data: {
            mobilePhone: phoneNumber,
            enterpriseId,
          }
        });

        if (res.retCode === 0) {
          this.pointInfo = res.data
        }
        const res1 = await this.$Request({
          url: "/getIntegralWaresInfo",
          method: "GET",
          data: {
            stationId: this.sid,
          }
        });

        if (res1.retCode === 0) {
          if(res1.data.isCouponProduct == 1){
            this.couponList = res1.data.couponIssue.couponTemplateList
            this.couponListInfo = res1.data.couponIssue
            this.isCouponProduct = res1.data.isCouponProduct
          }
          this.ware = res1.data;
        }
      } catch (error) {
        
      }
    },
    exchange() {
      if (this.ware.waresCount <= 0) {
        alert("该商品库存不足");
      } else if (this.ware.saleIntegral > this.pointInfo.points) {
        alert("您的积分不足");
      } else {
        uni.navigateTo({
          url: `/subPackB/point/pay/_sid/_pid?sid=${this.sid}&id=${this.id}`
        })
      }
    },
  },
};
</script>

<style lang="scss">
.point-detail {
  display: flex;
  width: 100vw;
  flex-direction: column;
  box-sizing: border-box;
  background: #f8f8f8;
}
.point-detail .good {
  box-sizing: border-box;
  width: 100vw;
  height: 100vw;
  padding: 15vw;
  background: #ffffff;
}
.point-detail .good img {
  width: 100%;
  height: 100%;
}
.point-detail .title {
  width: 100%;
  height: 26.66vw;
  padding: 4vw;
  background: #ffffff;
  position: relative;
  box-sizing: border-box;
}
.point-detail .title .text {
  width: 360rpx;
  height: 50rpx;
  font-size: 36rpx;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 800;
  color: #111111;
  line-height: 50rpx;
  position: absolute;
  left: 30rpx;
  top: 30rpx;
}
.point-detail .title .price {
  height: 70rpx;
  font-size: 28rpx;
  font-family: PingFangSC-Semibold, PingFang SC;
  font-weight: 600;
  color: #fe9700;
  line-height: 70rpx;
  position: absolute;
  left: 57rpx;
  bottom: 27rpx;
}
.point-detail .title .price .icon {
  display: inline-block;
  width: 30rpx;
  height: 30rpx;
  background: url("../../../static/point/a01_jifen@2x.png") no-repeat;
  background-size: cover;
  margin-right: 10rpx;
}
.point-detail .title .price .amount {
  display: inline-block;
  font-size: 50rpx;
}
.point-detail .title .sold {
  height: 40rpx;
  font-size: 28rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #666666;
  line-height: 40rpx;
  position: absolute;
  right: 45rpx;
  bottom: 30rpx;
}
.point-detail .selected {
  width: 100%;
  height: 110rpx;
  background: #ffffff;
  margin-top: 20rpx;
  position: relative;
}
.point-detail .selected .text {
  width: 56rpx;
  height: 110rpx;
  font-size: 28rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #aaaaaa;
  line-height: 110rpx;
  position: absolute;
  left: 31rpx;
  top: 0;
}
.point-detail .selected .content {
  width: 309rpx;
  height: 110rpx;
  font-size: 28rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 500;
  color: #111111;
  line-height: 110rpx;
  position: absolute;
  left: 117rpx;
}
.point-detail .selected .icon {
  width: 42rpx;
  height: 10rpx;
  background: url("../../../static/point/6_d02_more.png") no-repeat 0px 0px;
  background-size: cover;
  position: absolute;
  left: 630rpx;
  top: 49rpx;
}
.point-detail .pictures {
  width: 100%;
  height: 320rpx;
  background: #ffffff;
  margin-top: 21rpx;
  position: relative;
}

.point-detail .pictures .text {
  width: 174rpx;
  height: 110rpx;
  font-size: 28rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #aaaaaa;
  line-height: 110rpx;
  position: absolute;
  top: 0;
  left: 288rpx;
}
.point-detail .buy {
  position: fixed;
  bottom: 83rpx;
  left: 0;
  right: 0;
  height: 103rpx;
}

.point-detail .buy button {
  border: none;
  background-color: transparent;
  outline: none;
  display: block;
  width: 690rpx;
  height: 80rpx;
  background: #fe9700;
  border-radius: 45rpx;
  font-size: 28rpx;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
  line-height: 40rpx;
  margin: 0 auto;
}
.point-detail > .center {

    width: 700rpx;
    margin: 0 auto;
    >.title{
      text-align: center;
      height: 60rpx;
      line-height: 60rpx;
      margin: 0;
      padding: 0;
      font-size: 27rpx;
    }
    .coupon {
      display: flex;
      justify-content: space-between;
      height: 250rpx;
      margin-bottom: 30rpx;
      box-shadow: 0 0 10rpx 4rpx rgba(233, 223, 223, 0.5);
      > .left {
        display: flex;
        flex-direction: column;
        justify-content: center;
        text-align: center;
        width: 220rpx;
        height: 250rpx;
        text-align: center;

        .amount {
          display: block;
          font-size: 40rpx;
          font-weight: 500;
          color: #ffffff;
          line-height: 56rpx;
          text-align: center;
          margin-top: 0;
          .value {
            font-size: 60rpx;
          }
        }
        .condition {
          font-size: 24rpx;
          font-weight: 400;
          color: #ffffff;
          line-height: 33rpx;
          text-align: center;
          margin-top: 25rpx;
        }
        .exchangeName {
          display: none;
          font-size: 35rpx;
          font-weight: 500;
          color: #ffffff;
          line-height: 56rpx;
        }
      }
      > .right {
        width: 456rpx;
        height: 245rpx;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        margin: 8rpx 0 5rpx 0;
        .title {
          height: 30rpx;
          font-size: 24rpx;
          font-weight: 600;
          line-height: 33rpx;
          .type {
            width: 113rpx;
            height: 30rpx;
            line-height: 30rpx;
            display: inline-block;
            background: #f8c;
            border-radius: 19rpx;
            font-size: 24rpx;
            font-weight: 600;
            color: #ffffff;
            text-align: center;
          }
          .state {
            margin-left: 20rpx;
            color: #7f7f7f;

            height: 33rpx;
            font-size: 24rpx;
            font-weight: 600;
            line-height: 33rpx;
          }
        }
        .content {
          display: flex;
          justify-content: space-between;
          margin: 5rpx 0 5rpx 0;
          height: 140rpx;

          .items {
            width: 430rpx;
            height: 100%;
            display: flex;
            justify-content: space-around;
            flex-direction: column;
            .item {
              color: #272626;
              font-size: 21rpx;
              > text {
                width: 330rpx;
                display: inline-block;
                color: #272626;
                font-size: 22rpx;
                font-weight: bold;
                overflow: scroll; /* 超出部分隐藏 */
                white-space: nowrap; /* 文本不换行 */
              }
            }
            .from {
              display: block;
            }
          }
          > .btn {
            display: flex;
            flex-direction: column;
            justify-content: center;
            margin-right: 10rpx;
            > button {
              height: 60rpx;
              background: linear-gradient(143deg, #fad965 0%, #f3b235 100%);
              border-radius: 20rpx;
              border: none;
              outline: none;
              color: #ffffff;
              line-height: 33rpx;
              font-size: 30rpx;
              font-weight: 400;
              overflow: hidden; /* 超出部分隐藏 */
              white-space: nowrap; /* 文本不换行 */
              display: none;
            }
          }
        }
        .notip {
          height: 180rpx;
        }
        .tip {
          margin-right: 20rpx;
          border-top: 2rpx dashed #d8d8d8;
          height: 49rpx;
          font-size: 22rpx;
          font-weight: 400;
          color: #7f7f7f;
          line-height: 23rpx;
          padding-top: 12rpx;
          box-sizing: border-box;
          overflow: scroll; /* 超出部分隐藏 */
          white-space: nowrap;
          /*  text-overflow: ellipsis;*/
        }
      }
    }
    .direct {
      > .left {
        background: url("../../../static/coupon/quan1.2x.png") no-repeat;
        background-size: 100% 100%;
      }
      > .right {
        > .title > .type {
          background: #f8ce57;
        }
        > .content > .btn button {
          background: linear-gradient(143deg, #fad965 0%, #f3b235 100%);
        }
      }
    }
    .rate {
      > .left {
        background: url("../../../static/coupon/quan2.2x.png") no-repeat;
        background-size: 100% 100%;
      }
      > .right {
        > .title > .type {
          background: #eb8573;
        }
        > .content > .btn button {
          background: linear-gradient(143deg, #f4a796 0%, #e67462 100%);
        }
      }
    }
    .exchange {
      > .left {
        background: url("../../../static/coupon/quan3.2x.png") no-repeat;
        background-size: 100% 100%;
        > .amount,
        > .condition {
          display: none;
        }
        > .exchangeName {
          display: inline-block;
          width: 150rpx;
          margin: 0 auto;
        }
      }
      > .right {
        > .title > .type {
          background: #19c79b;
        }
        > .content {
          > .items {
            width: 330rpx;
            .item text {
              width: 230rpx;
            }
          }
          > .btn button {
            background: linear-gradient(143deg, #21d9b4 0%, #0fb582 100%);
            display: block;
          }
        }
      }
    }
    .expired {
      > .left {
        background: url("../../../static/coupon/quan4.2x.png") no-repeat;
        background-size: 100% 100%;
      }
      > .right {
        > .title > .type {
          background: #bfbfbf;
        }
        > .content > .btn button {
          display: none;
        }
      }
    }
  }
</style>
